cmake_minimum_required(VERSION 3.0.10)
project(tuw_voronoi_graph)

add_compile_options(-std=c++14)
add_compile_options(-Wall)

find_package(catkin REQUIRED COMPONENTS
        dynamic_reconfigure
        cv_bridge
        geometry_msgs
        nav_msgs
        roscpp
        tf
        tuw_multi_robot_msgs
        )

find_package(Boost COMPONENTS serialization filesystem program_options REQUIRED)
find_package(Eigen3 REQUIRED)

set(_opencv_version 4)
find_package(OpenCV 4 QUIET)
if (NOT OpenCV_FOUND)
    message(STATUS "Did not find OpenCV 4, trying OpenCV 3")
    set(_opencv_version 3)
endif ()

find_package(OpenCV ${_opencv_version} REQUIRED
        COMPONENTS
        opencv_core
        opencv_imgproc
        opencv_imgcodecs
        CONFIG
        )

find_library(DXF_LIB dxflib)
if (NOT DXF_LIB)
    message(WARNING "dxf library not found")
    message(WARNING "run 'sudo apt install libdxflib-dev' to install the dxf library")
endif ()

catkin_package(
        #  INCLUDE_DIRS include
        #  LIBRARIES tuw_voronoi_graph
        CATKIN_DEPENDS dynamic_reconfigure cv_bridge geometry_msgs nav_msgs roscpp tf tuw_multi_robot_msgs
        #  DEPENDS OpenCV
)

include_directories(
        include
        ${catkin_INCLUDE_DIRS}
)
add_library(graph_serialization_lib src/serializer.cpp)
add_library(voronoi_path_lib src/voronoi_path_generator.cpp src/thinning.cpp)
add_library(voronoi_graph_lib
        src/voronoi_graph_generator.cpp
        src/segment.cpp
        src/segment_expander.cpp
        src/crossing.cpp)
add_library(dxf_graph_lib src/dxf_to_graph.cpp src/dxf_line_arc_parser.cpp)

target_link_libraries(graph_serialization_lib ${catkin_LIBRARIES} ${OpenCV_LIBRARIES} ${Boost_SERIALIZATION_LIBRARY})
target_link_libraries(voronoi_path_lib ${catkin_LIBRARIES} ${OpenCV_LIBRARIES})
target_link_libraries(voronoi_path_lib graph_serialization_lib voronoi_graph_lib ${catkin_LIBRARIES} ${OpenCV_LIBRARIES})
target_link_libraries(dxf_graph_lib graph_serialization_lib voronoi_graph_lib ${catkin_LIBRARIES} ${OpenCV_LIBRARIES} ${Boost_PROGRAM_OPTIONS_LIBRARY} dxflib)

add_executable(tuw_voronoi_graph_node src/voronoi_graph_node.cpp)
add_executable(tuw_dxf_graph_node src/dxf_to_graph_node.cpp)
add_executable(tuw_segment_to_graph_node src/segment_to_graph_node.cpp)
add_executable(tuw_segment_to_graph_test src/segment_to_graph_test.cpp
        src/voronoi_path_generator.cpp src/thinning.cpp
        src/voronoi_graph_generator.cpp src/segment.cpp src/segment_expander.cpp src/crossing.cpp
        src/serializer.cpp
        src/dxf_to_graph.cpp src/dxf_line_arc_parser.cpp
        )
target_link_libraries(tuw_voronoi_graph_node voronoi_path_lib)
target_link_libraries(tuw_dxf_graph_node dxf_graph_lib)
target_link_libraries(tuw_segment_to_graph_node ${catkin_LIBRARIES} yaml-cpp)
target_link_libraries(tuw_segment_to_graph_test yaml-cpp dxflib ${catkin_LIBRARIES} ${OpenCV_LIBRARIES} ${Boost_SERIALIZATION_LIBRARY})

add_dependencies(voronoi_path_lib ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
add_dependencies(tuw_segment_to_graph_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

# Mark executables and/or libraries for installation
install(TARGETS voronoi_path_lib voronoi_graph_lib dxf_graph_lib graph_serialization_lib tuw_voronoi_graph_node tuw_dxf_graph_node tuw_segment_to_graph_node
        ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
        LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
        RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
        )

## Mark config files for installation
install(DIRECTORY cfg/
        DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/cfg
        )

## Mark launch files for installation
install(DIRECTORY launch/
        DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/launch
        )

